

#include("/WEB-INF/admin/common/header.html")
<body class="childrenBody">
	<form class="layui-form layadd">
		<div class="layui-form-item">
			<label class="layui-form-label">角色名称：</label>
			<div class="layui-input-block">
				<input type="text"  class="layui-input " name="role.name" lay-verify="required" >
			</div>
		</div>
		
		<div class="layui-form-item">
			<label class="layui-form-label">角色描述：</label>
			<div class="layui-input-block">
			<input type="text" lay-verify="required" name="role.description"   placeholder="" autocomplete="off" class="layui-input">
			</div>
		</div>
	
	<div class="layui-table-diaglo">	
		<table  id="roleaddTable" lay-filter="roleaddTable"></table>
	</div>
	
  	<input type="hidden" name="orderIndexs" value="" id="ids">
		<div class="layui-form-item layui-affirm">
			<button class="layui-btn" lay-submit="" id="roleadd" lay-filter="roleadd">确定</button>    	
		</div>
 </form>
 <script type="text/javascript" src="#(BASE_PATH)/static/layui/layui.js"></script>
<script >
layui.use(['table','laydate','form','jquery','treeGrid'],function(){
		 var form = layui.form,
		 	$ = layui.jquery,
		 	table = layui.table,
		 	laydate=layui.laydate;
		 var treeGrid = layui.treeGrid; //很重要
		 treeGrid.render({
 		    elem: '#roleaddTable',
	        	url:'#(BASE_PATH)/security/role/addPageJson',
	        	cellMinWidth: 80,
	        	id: 'roleaddTable',
	        	treeId:'id',
	        	treeUpId:'parent_menu',
	        	treeShowName:'name',
		        cols: [[
						{type:'checkbox'},
		                {field: 'name', title: '权限名',unresize:true},
		                {field: 'description', title: '权限描述',unresize:true},
		                ]],  
		               done: function(res, curr, count) {
		                                   
		               },
		        loading: true,
 		  });
 			//监听表格复选框选择
			 $("#roleadd").click(function(){
				 var checkedArr=[];
				 table.on('checkbox(roleaddTable)', function(obj){
					 if (obj.type=='all') return;
					 if (obj.checked){
					 	checkedArr[obj.data.id] = obj.data.LAY_TABLE_INDEX;
					 }
					 else{
					 	delete checkedArr[obj.data.id];
					 }
				 });
				 var checkStatus = table.checkStatus('roleaddTable')
				 	,data = checkStatus.data, tmpArr = [], ids = [];
				 if (checkStatus.isAll){
					 for (var i=0; i<data.length ; i++){
					 	checkedArr[data[i].id]=i;
					 	ids.push(data[i].id);
					 }
				 }
				 else{ 
					 for (var i=0; i<data.length ; i++){
						 tmpArr[data[i].id]=checkedArr[data[i].id];
						 ids.push(data[i].id);
					 }
					 checkedArr = tmpArr;
				 }
				 ids=ids.toString();
				 console.log(ids);
			  $("#ids").val(ids);
				 console.log( $("#ids").val());
			 })
    	      //添加
    		  form.on('submit(roleadd)', function(data) {
    			  $.post('/security/role/save',data.field,function(msg){
     	    		 if(msg.statusCode==200){
     	    			 
     	    			 layer.msg(msg.message, {time: 1000},function(){
     	    				parent.layer.closeAll();
     	    				parent.tableReload();
     	    			 });  			
     	    		 }else{
     	    			
     	    			 layer.open({
     	    			        type: 1,				       
     	    			        id: 'message',
     	    			        content: '<div style="padding: 20px 100px;">'+ msg.message +'</div>',
     	    			        btn: '确定',
     	    			        btnAlign: 'c',
     	    			        shade: 0.4 ,
     	    			        yes: function(){
     	    			         layer.closeAll();
     	    			        }
     	    			    });
     	    		 }		 
     	    	  });
     	          return false;
    		    });
    	      
})

</script>
</body>
</html>
